 'use strict';
 const fs = require('mz/fs');
const path = require('path');
// const cache = require('memory-cache');

 module.exports = app => {
   app.beforeStart(async () => {

  
     const env = app.config.env;
    //  app.helper.saveCach('rate',0.02)
     if (env === 'local') {
      app.logger.debug()
       const localDir =  path.join(app.baseDir,  '../public','img') ;//public文件夹还是要建立
      console.debug("文件夹路径 >>>>>>>>>>",localDir);

      //  console.log("=-",localDir);   
       if (!fs.existsSync(localDir)) { //开发环境
         await fs.mkdir(localDir)
       }

     } else if (env === 'production' || env === 'prod') {
        const prodDir = '/home'

     }

     await app.model.sync({
       force: false
     }); //自动根据model进行建立表 force一定要用false


   });

   

   // app.messenger.on('egg-ready', info => {
   //   console.info("本服务端口",info.port);
   // });
  

 };

//  class AppBootHook { //放在此报错
//   constructor(app) {
//     this.app = app;
//   }
  
//    async willReady() {
//     //  
//     this.app.cache = new cache();
//     this.app.cache.put("rate",0.02);
//     console.log("今天收益率",this.app.cache.get("rate") ) 

//   }

// }
// module.exports = AppBootHook;
 